﻿/*
{
"状态":1,
"名称":"修改-公司资料",
"作者":"陈泽椿",
"创建时间":"2018-06-30",
"功能":"修改-公司资料",
"log": [
	{"date":"06-01" , "dev" :"hzhh" , "content" : ""}
]
}
*/
declare @company_key int ,@company_id varchar(100),@company_name varchar(100)
declare @telphone varchar(100),@address varchar(100),@legal_person varchar(100)

set @company_key = '{company}'
set @company_id = '{company_id}'
set @company_name = '{company_name}'
set @telphone ='{telphone}' 
set @address = '{address}'
set @legal_person = '{legal_person}'



--校验信息
if isnull(@company_id,'')=''
begin 
	RAISERROR ('SQL:公司id不允许为空', 16 ,1 ) ; 
	return
end 

if isnull(@company_name,'')=''
begin 
	RAISERROR ('SQL:公司名称不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@telphone,'')=''
begin 
	RAISERROR ('SQL:联系电话不允许为空', 16 ,1 ) ; 
	return 
end 

if isnull(@address,'')=''
begin 
	RAISERROR ('SQL:联系地址', 16 ,1 ) ; 
	return 
end 

if isnull(@legal_person,'')=''
begin 
	RAISERROR ('SQL:法人', 16 ,1 ) ; 
	return 
end 

IF EXISTS(SELECT * FROM y_company WHERE company_key<>@company_key and company_id=@company_id)
begin
	RAISERROR ('SQL:公司id已经存在', 16 ,1 ) ; 
	return 
end  
 
update [dbo].[y_company] set
[company_id] = @company_id ,
[company_name] = @company_name ,
[telphone] = @telphone , 
[address] = @address ,
[legal_person] = @legal_person ,  
[update_time] = getdate()
where [company_key] = @company_key
